﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace class6Homework
{
    public partial class Form1 : Form
    {
        string file_1Name;
        string file_2Name;
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            file_1Name = @"C:\Users\16427\Desktop\" + textBox1.Text;
            label3.Text = "文本文件1已录入";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            file_2Name = @"C:\Users\16427\Desktop\"+textBox2.Text;
            label4.Text = "文本文件2已录入";
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if(file_1Name==null&&file_2Name==null)
            {
                label6.Text = "请输入文件1和文件2的文件名";
            }
            else if(file_1Name==null&&file_2Name!=null)
            {
                label6.Text = "请输入文件1文件名";
            }
            else if(file_1Name!=null&&file_2Name==null)
            {
                label6.Text = "请输入文件2文件名";
            }
            FileStream file1 = new FileStream(file_1Name, FileMode.Open, FileAccess.ReadWrite);
            FileStream file2 = new FileStream(file_2Name, FileMode.Open, FileAccess.ReadWrite);
            FileStream file3 = new FileStream(@"C:\Users\16427\source\repos\class6Homework\data\new_txt_file.txt", FileMode.Create, FileAccess.ReadWrite);
            StreamReader f_1Out = new StreamReader(file1);
            StreamReader f_2Out = new StreamReader(file2);
            StreamWriter f_3In = new StreamWriter(file3);
            string s1 = f_1Out.ReadLine();
            while(s1!=null)
            {
                f_3In.WriteLine(s1);
                s1 = f_1Out.ReadLine();
            }
            string s2 = f_2Out.ReadLine();
            while (s2 != null)
            {
                f_3In.WriteLine(s2);
                s2 = f_2Out.ReadLine();
            }
            f_1Out.Close();
            f_2Out.Close();
            f_3In.Close();
            label6.Text = "新文件3已在C:\\Users\\16427\\source\\repos\\class6Homework\\data处成功创建";



        }
    }
}
